use std::sync::Arc;
use sqlx::MySqlPool;
use crate::business::entity::user_post::UserPost;
use crate::extends::core::pager::page_helper::PageHelper;
use crate::extends::core::response::result_data::ResultData;

#[derive(Clone,Debug)]
pub struct UserPostService {
    pool: Arc<MySqlPool>,
}

impl UserPostService {
    pub fn new(pool: MySqlPool) -> Self {
        Self {
            pool: Arc::new(pool),
        }
    }

    pub async fn save(&self, user_post: &UserPost) -> Option<i32> {
        UserPost::save(user_post, &self.pool).await
    }

    pub async fn update(&self, user_post: &UserPost) -> Option<bool> {
        UserPost::update(user_post, &self.pool).await
    }

    pub async fn delete(&self, id: &i32) -> Option<bool> {
        UserPost::delete(id, &self.pool).await
    }

    pub async fn find_by_id(&self, id: &i32) -> Option<UserPost> {
        UserPost::find_by_id(id, &self.pool).await
    }

    pub async fn find_by_count(&self, user_post: &UserPost) -> Option<i64> {
        UserPost::find_by_count(user_post, &self.pool).await
    }

    pub async fn find(&self, search: &PageHelper<UserPost>) -> ResultData<UserPost> {
        UserPost::find(search, &self.pool).await
    }

    // 其他方法可以在此处添加...
}
